package com.prs.crm.dao.cdxh.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cdxh.StockPrecautionaryDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cdxh.StockPrecautionary;
import com.prs.crm.domain.cdxh.production.ProvideRegime;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-13 下午05:50:05
 * 简单说明
 */

public class StockPrecautionaryDaoImpl extends BaseDaoImpl<StockPrecautionary>
		implements StockPrecautionaryDao {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public StockPrecautionary getStockPrecautionaryByProductId(final String productId) {
		return (StockPrecautionary) this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException {
						Criteria criteria = session
								.createCriteria(StockPrecautionary.class);
						criteria.add(Restrictions.eq("productCode", productId));
						List<StockPrecautionary> result = criteria.list();
						if (result.size() == 0) {
							return null;
						} else {
							return result.get(0);
						}
					}
				});
	}

	@Override
	public void saveOrStockPrecautionary(StockPrecautionary stockPrecautionary) {
		this.getHibernateTemplate().saveOrUpdate(stockPrecautionary);
		
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<StockPrecautionary> getStockPrecautionaryList() {
		return (List<StockPrecautionary>) this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException {
						Criteria criteria = session
								.createCriteria(StockPrecautionary.class);
						List<StockPrecautionary> result = criteria.list();
						if (result.size() == 0) {
							return null;
						} else {
							return result;
						}
					}
				});
	}

	@Override
	public void setById(StockPrecautionary kl) {
		this.getHibernateTemplate().delete(kl);
	}

}
